<template>
  <div class="redirect">
    <div class="view" v-if="msg">
      <div> <i class="el-icon-warning"></i> 诶呀，出错了</div>
      <div>{{ msg }}</div>
    </div>
  </div>
</template>

<script setup>
import {onMounted, ref} from "vue";
import {GlobalConfig} from 'core';
const {appConfig} = GlobalConfig();
let msg = ref(null)

const getUrlParmas = ()=> {
  let url = window.location.href
  let parmas = url.split('?')[1]
  let parmasFn = new URLSearchParams(parmas)
  return parmasFn
}

const router = useRouter();

onMounted((query)=>{
  console.log(appConfig.home)
  let token = getUrlParmas().get('token')

  let errMsg = getUrlParmas().get('errorMsg')

  if(!Helper.empty(errMsg)) {
    msg.value = errMsg
    return
  }

  if(Helper.empty(token)) {
    msg.value = '登陆失败，请重新尝试'
    return
  }

  Cache.setToken(token);
  router.replace({path: appConfig.home});
})


</script>

<style lang="less" scoped>
.redirect{
  width: 100%;
  height: 100vh;

  display: flex;
  justify-content: center;
  align-items: center;

  .view{
    width: 500px;
    height: 500px;

    div:nth-child(1) {
      font-size: 30px;
      text-align: center;
      font-weight: 600;
    }

    div:nth-child(2) {
      margin-top: 20px;
      font-size: 20px;
      text-align: center;

      max-height: 300px;
      overflow-y: auto;
    }

    div:nth-child(3) {
      margin-top: 20px;
      font-size: 20px;
      text-align: center;
    }
    div:nth-child(4) {
      margin-top: 30px;
      font-size: 20px;
      text-align: center;
    }
  }
}
</style>
